# -*- coding:utf-8 -*-

# @Time    : 2018/9/27 2:32 PM

# @Author  : Swing


import pandas as pd
from sklearn.preprocessing import StandardScaler


def process(train):

    print(train.describe())

    categorical_features = ['season', 'mnth', 'weathersit', 'weekday']
    for col in categorical_features:
        print(col, '属性的不同取值和出现的次数')
        print(train[col].value_counts())
        train[col] = train[col].astype('object')
    x_train_cat = train[categorical_features]

    x_train_cat = pd.get_dummies(x_train_cat)
    print(x_train_cat.head())

    # 数值型变量预处理
    # 标准化
    ss_x = StandardScaler()
    # mn_x = MinMaxScaler()
    numerical_features = ['temp', 'hum', 'windspeed']
    # temp = mn_x.fit_transform(train[numerical_features])
    temp = ss_x.fit_transform(train[numerical_features])

    x_train_num = pd.DataFrame(data=temp, columns=numerical_features, index=train.index)
    print(x_train_num.head())

    # y 标准化
    y = train[['cnt']]
    ss_y = StandardScaler()
    temp_y = ss_y.fit_transform(y)
    y_train_num = pd.DataFrame(data=temp_y, columns=['cnt'], index=train.index)

    # 连接类别型和数字型特征
    # x_train = pd.concat([x_train_cat, x_train_num, train['holiday'], train['workingday']], axis=1, ignore_index=False)
    # print(x_train.head())
    #
    # fe_train = pd.concat([x_train,  y_train_num], axis=1)
    fe_train = pd.concat([x_train_cat, train['holiday'], train['workingday'], x_train_num, y_train_num],
                          axis=1, ignore_index=False)
    fe_train.to_csv('files/FE_day.csv', index=False)
    print(fe_train.head())
    fe_train.info()

